<?php
include '../../../common.inc.php';
set_time_limit(0);
include __DIR__ . '/auto.func.php';
$startTime = microtime(true);
$start = isset($start) ? intval($start) : 0;
$sql = "select * from xd_auto_handler where ischeck=0 and id={$start} order by id asc limit 1 ";
$one = $db->getOne($sql);
// $folder = "F:/Auto/比亚迪/比亚迪e6图片/";
// 3.5s
if (!$one) {
	exit('Handler Over');
} else {
	$folder = "F:/Picture/乘用车/{$one['first']}/{$one['second']}/";
}
//$folder = "F:/Auto/MG/AUSTIN SEVEN图片/";
$folderEncode = mb_convert_encoding($folder,"GB2312","UTF-8,GBK");

// 获取子目录所有分类
$picTypes = getDir($folderEncode);
$needCreateFirst = array();
$needMove = array();
foreach($picTypes as $v) {
	$pathEncode = $folderEncode.$v.'/';
	$in_array = in_array(_($v), array('底盘', '图解', '试车', '空间', '内饰', '空间', '外观', '细节', '车展', '官方图', '试车', '活动', '活动', '活动', '活动', '活动', '活动'));
	
	if ($in_array) {
		print_r(_($pathEncode).'<br/>');
		$carTypes = getDir($pathEncode);
		if ($carTypes) {
			foreach($carTypes as $cv) {
				$needMove[] = $pathEncode.$cv.'/';
			}
		}
	}
}

if ($needMove) {
	foreach($needMove as $v) {
		$folderOld = $v;
		$folderNew = getFolderNew($folderOld);
		if (!file_exists($folderNew)) {
			mkdir($folderNew, 0777, true);
		}
		dir_copy($folderOld, $folderNew);
		File::dirDelete($folderOld);
		rmdir($folderOld);
		rmdir(dirname($folderOld));
	}
	$endTime = microtime(true);
	$time = $endTime - $startTime;
	$sql = "update xd_auto_handler set  ischeck=1, vtime='{$time}' where id = {$one['id']}";
	if(!$db->query($sql)){
		exit('Hander Wrong!');
	}
}
$start+=1;
echo '<meta http-equiv="refresh" content="0; url='.$_SERVER['PHP_SELF'].'?start='.$start.'" />';
exit();